﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Xml;

namespace DateReminder
{
    public partial class ucMain : UserControl
    {
        public ucMain()
        {
            Debug.WriteLine(DateTime.Now + " DEBUG: PLugin DateReminder.dll běží v {0} s  AppDomainID = {1}.", Thread.GetDomain().FriendlyName, Thread.GetDomainID());


            InitializeComponent();
            this.Dock = System.Windows.Forms.DockStyle.Fill;

            //List<Event> events = new List<Event>();
            //events.Add(new Event(Convert.ToDateTime("12.06.2012"), "Prvni event", 1));
            //events.Add(new Event(Convert.ToDateTime("13.06.2012"), "Druhy event", 2));
            //events.Add(new Event(Convert.ToDateTime("12.8.2012"), "Treti event", 3));
            //events.Add(new Event(Convert.ToDateTime("12.8.2013"), "Ctvrty event", 4));

            //dgEvents.DataSource = events;
            //dgEvents.ColumnCount = 3;
            DataSet ds = new DataSet();

            CalendarColumn col = new CalendarColumn();
            col.Name = "Date";
            dgEvents.Columns.Add(col);
            dgEvents.Columns.Add("IEvent", "Event Description");

            DataGridViewComboBoxColumn cmb = new DataGridViewComboBoxColumn();
            cmb.HeaderText = "Event Priority";
            cmb.Name = "IEvent";
            cmb.MaxDropDownItems = 4;
            cmb.Items.Add("1");
            cmb.Items.Add("2");
            cmb.Items.Add("3");
            cmb.Items.Add("4");
            dgEvents.Columns.Add(cmb);
            //dgEvents.DataSource = ds;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            XmlDocument doc = new XmlDocument();
            XmlNode root = doc.CreateElement("Events");
            // storing Each row and column value
            for (int i = 0; i < dgEvents.Rows.Count - 1; i++)
            {
                XmlNode nodeEvent = doc.CreateElement("Event");
                XmlNode nodeDate = doc.CreateElement("Date");
                XmlNode nodeDescription = doc.CreateElement("Description");
                XmlNode nodePriority = doc.CreateElement("Priority");

                nodeDate.InnerText = dgEvents.Rows[i].Cells[0].Value.ToString();
                nodeDescription.InnerText = dgEvents.Rows[i].Cells[1].Value.ToString();
                nodePriority.InnerText = dgEvents.Rows[i].Cells[2].Value.ToString();

                nodeEvent.AppendChild(nodeDate);
                nodeEvent.AppendChild(nodeDescription);
                nodeEvent.AppendChild(nodePriority);

                root.AppendChild(nodeEvent);


                //XmlAttribute att = doc.CreateAttribute("type");
                //att.InnerText = "integer";
                //n.InnerText = r.Next(100).ToString();
                //n.Attributes.Append(att);
                //// nakonec element pridame do korene dokumentu
                //root.AppendChild(n);


                //for (int j = 0; j < dgEvents.Columns.Count; j++)
                //{
                //    worksheet.Cells[i + 2, j + 1] = dgEvents.Rows[i].Cells[j].Value.ToString();
                //}
            }
            doc.AppendChild(root);
            doc.Save("test.xml");



            //// storing header part in Excel
            //for (int i = 1; i < dgEvents.Columns.Count + 1; i++)
            //{
            //    worksheet.Cells[1, i] = dgEvents.Columns[i - 1].HeaderText;
            //}








        }
    }
}
